package com.eastmountain.chinese.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.eastmountain.util.DisplayFormats;

public class ToneMarks {
    
    public static String remove( String toneMarkedString ) {
        
        Pattern pattern = null;
        Matcher matcher = null;
        
        String unmarkedString = toneMarkedString;

        String toned = DisplayFormats.stringToHex( toneMarkedString );

        for ( String[] element : matchAndRelace ) {

            pattern = Pattern.compile( element[ 1 ] );
            matcher = pattern.matcher( unmarkedString );
            
            if ( matcher.find() ) {  
            
                unmarkedString = matcher
                                .replaceAll( element[ 0 ] );
                
            }

                //System.out.printf( "%d - %s - %s\n", i,
                //                   matchAndRelace[i][MATCH],
                //                   matchAndRelace[i][REPLACE] );

        }
/*        
        for ( int i = 0; i < matchAndRelace.length; i++ ) {
            
            unmarkedString.replaceAll( matchAndRelace[ i ][ 1 ], matchAndRelace[ i ][ 0 ] );
            
        } 
        
        //unmarkedString = toneMarkedString;
*/        
        return( unmarkedString );
        
    }

private static String a1 = "\u0101"; /* a1 - 257 */
private static String a2 = "\u00e1"; /* a2 - 225 */
private static String a3 = "\u01ce"; /* a3 - 462 */
private static String a4 = "\u00e0"; /* a4 - 224 */
private static String e1 = "\u0113"; /* e1 - 275 */
private static String e2 = "\u00e9"; /* e2 - 233 */
private static String e3 = "\u011b"; /* e3 - 283 */
private static String e4 = "\u00e8"; /* e4 - 232 */
private static String i1 = "\u012b"; /* i1 - 299 */
private static String i2 = "\u00ed"; /* i2 - 237 */
private static String i3 = "\u01d0"; /* i3 - 464 */
private static String i4 = "\u00ec"; /* i4 - 236 */
private static String o1 = "\u014d"; /* o1 - 333 */
private static String o2 = "\u00f3"; /* o2 - 243 */
private static String o3 = "\u01d2"; /* o3 - 466 */
private static String o4 = "\u00f2"; /* o4 - 242 */
private static String u1 = "\u016b"; /* u1 - 363 */
private static String u2 = "\u00fa"; /* u2 - 250 */
private static String u3 = "\u01d4"; /* u3 - 468 */
private static String u4 = "\u00f9"; /* u4 - 249 */

private static String[][] matchAndRelace
            = { { "a", a1 },
                { "a", a2 }, { "a", a3 },
                { "a", a4 }, { "e", e1 },
                { "e", e2 }, { "e", e3 },
                { "e", e4 }, { "i", i1 },
                { "i", i2 }, { "i", i3 },
                { "i", i4 }, { "o", o1 },
                { "o", o2 }, { "o", o3 },
                { "o", o4 }, { "u", u1 },
                { "u", u2 }, { "u", u3 }, { "u", u4 } };


}

